<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/1
 * Time: 22:47
 */

namespace app\api\model;


class Order extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $hidden= ['delete_time','user_id','update_time'];

    public function getSnapItemsAttr($value){
        if(!$value){
            return null;
        }
        return json_decode($value);
    }

    public function getSnapAddressAttr($value){
        if(!$value){
            return null;
        }
        return json_decode($value);
    }


    public static function getOrderDetail($id){
        return self::where('id','=',$id)->find();
    }

    public static function getOrders( $size, $page,$type)
    {
        return self::where('order_type','=', $type)->order('create_time desc')->paginate($size,true,['page'=>$page]);
    }

    //分页展示
    public static function getOrderList($uid, $size, $page ,$type)
    {
        return self::where('user_id','=', $uid)-> where('order_type','=', $type)-> order('create_time desc')->paginate($size,true,['page'=>$page]);
    }
}